package com.bupt.greeddaotest.control;

import android.app.Application;
import android.database.sqlite.SQLiteDatabase;

import com.bupt.greeddaotest.dao.DaoMaster;
import com.bupt.greeddaotest.dao.DaoSession;

import org.greenrobot.greendao.database.Database;

/**
 * application的基类
 */

public class MeApplication extends Application {

    private static MeApplication application;
    private MySQLiteOpenHelper openHelper;
//    private Database db;
    private SQLiteDatabase db;
    private DaoMaster daoMaster;
    private DaoSession daoSession;
    public static String pas = "www.baidu.com";
    public static String database_name = "record-db";


    @Override
    public void onCreate() {
        super.onCreate();
        application = this;
        setDatabase();
    }

    private void setDatabase() {
//        MigrationHelper.DEBUG = true; //如果你想查看日志信息，请将DEBUG设置为true
        openHelper = new MySQLiteOpenHelper(this, database_name, null);
//        db = openHelper.getEncryptedWritableDb(pas);
        db = openHelper.getWritableDatabase();
        daoMaster = new DaoMaster(db);
        daoSession = daoMaster.newSession();
    }

    public static MeApplication getMeApplication(){
        return application;
    }

    public DaoSession getDaoSession() {
        return daoSession;
    }


    public SQLiteDatabase getDb() {
        return db;
    }
}
